package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.AppMingxiJinbiDao;
import com.vf.admin.client.dao.AppUserDao;
import com.vf.admin.client.service.AppMingxiJinbiService;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppMingxiJinbi;
import com.vf.admin.miaodong.entity.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AppMingxiJinbiServiceImpl implements AppMingxiJinbiService {
    @Autowired
    private AppMingxiJinbiDao appMingxiJinbiDao;
    @Autowired
    private AppUserDao appUserDao;

    @Override
    public List<AppMingxiJinbi> findList(Integer userid, SplitPageBean splitPage) {
        return appMingxiJinbiDao.findList(userid, splitPage);
    }

    @Override
    public AppMingxiJinbi get(Integer id) {
        return appMingxiJinbiDao.get(id);
    }

    @Override
    public void save(AppMingxiJinbi haoYou) {
        appMingxiJinbiDao.save(haoYou);
    }
    @Override
    public void addMingxi(Integer userid, BigDecimal num, Integer leixing, String beizhu) {
        AppUser user=appUserDao.get(userid);
        AppMingxiJinbi zuanShi=new AppMingxiJinbi();
        zuanShi.setUserid(user.getId());
        zuanShi.setPic(user.getPic());
        zuanShi.setPhone(user.getLoginname());
        zuanShi.setNick(user.getNick());
        zuanShi.setLeixing(leixing);
        zuanShi.setNum(num);
        zuanShi.setCreatetime(new Date());
        zuanShi.setBeizhu(beizhu);
        appMingxiJinbiDao.save(zuanShi);
    }

    @Override
    public double jinbiGrowthSum(Integer userId) {
        Map<String, Object> params = new HashMap<>();
        params.put("leixing", 1);
        List<AppMingxiJinbi> list = appMingxiJinbiDao.findList(params, userId);
        double sum = list.stream().mapToDouble(e -> Long.valueOf(e.getNum().stripTrailingZeros().toPlainString())).sum();

        return sum;
    }

    @Override
    public List<AppMingxiJinbi> indexCount(Map<String, Object> params) {
        return appMingxiJinbiDao.indexCount(params);
    }

    @Override
    public List<AppMingxiJinbi> orgInfo(Map<String, Object> params, SplitPageBean splitPage) {
        return appMingxiJinbiDao.orgInfo(params,splitPage);
    }

    @Override
    public List<AppMingxiJinbi> countNum(Map<String, Object> params) {
        return appMingxiJinbiDao.countNum(params);
    }


}
